/*
 * 文件名: KeyBoardEditText.java
 * 版    权：  Copyright PingAn Technology All Rights Reserved.
 * 描    述: [该类的简要描述]
 * 创建人: EX-XUJIAO001
 * 创建时间: 2012-2-6
 * 
 * 修改人：
 * 修改时间:
 * 修改内容：[修改内容]
 */
package app.widget.PASafeKeyBoard;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Build;
import android.os.Handler;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
import android.text.Selection;
import android.text.TextWatcher;
import android.text.method.PasswordTransformationMethod;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ViewFlipper;
import app.log.APPLog;
import app.widget.PASafeKeyBoard.KeyBoardView.OnKeyDownBtnListener;
import app.widget.PASafeKeyBoard.KeyBoardView.OnKeyExitBtnListener;
import app.widget.PASafeKeyBoard.KeyBoardView.OnKeySureBtnListener;
import app.widget.PASafeKeyBoard.KeyBoardView.OnSwitchCharKeyBoardListener;
import app.widget.PASafeKeyBoard.KeyBoardView.OnSwitchKeyBoardListenter;

import com.longevityassistant.activity.R;

/**
 * @author EX-XUJIAO001
 * @date 2012-2-6
 * @version [Android PABank C01, @2012-2-6]
 * @description
 */
public class PAKeyBoardEditText extends EditText implements
		OnFocusChangeListener, OnClickListener, TextWatcher {

	/**
	 * 键盘视图
	 */
	private KeyBoardView keyBoardView;
	/**
	 * inflater
	 */
	private LayoutInflater inflater;
	/**
	 * 上下文
	 */
	private Context context;
	/**
	 * 得到window中某个控件的位置数组
	 */
	private int editLocations[] = new int[2];
	/**
	 * 屏幕的高度
	 */
	private int screenHeight;
	/**
	 * 是否移动过
	 */
	private boolean isMove = false;
	/**
	 * 输入方式默认为-1
	 */
	private int inputMethod = -1;
	/**
	 * 是否点击过
	 */
	private boolean isOnClick = false;
	/**
	 * 是否能以零开头
	 */
	private boolean isStartZero = true;
	/**
	 * 是否能以点开头
	 */
	private boolean isStartPoint = false;
	/**
	 * 是否为小数
	 */
	private boolean isDecimal = false;
	/**
	 * 输入法Manager
	 */
	private InputMethodManager imm;
	/**
	 * 是否为密码
	 */
	private boolean isPassword = false;
	/**
	 * 默认小数长度为2
	 */
	private int decimalLength = 2;

	/**
	 * 小数是否以零开头
	 */
	private boolean deciamlStartZero = false;

	private static final int KEYBOARD = -1;
	private static final int LETTERKEYBOARD = 2;

	private ViewFlipper viewFlipper;
	/**
	 * 整数部分的长度
	 */
	private int intergerLength;
	/**
	 * sdk版本号
	 */
	private int sdkVersion;
	/**
	 * 计数器
	 */
	private int count;
	
	/**
		密码黑点
	 */
	private static char DOT = '\u2022';
	
	private ViewFlipper charViewFlipper;

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 得到整数部分的长度
	 * 
	 * @return int
	 */
	public int getIntergerLength() {
		return intergerLength;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 设置整数部分的长度
	 * 
	 * @param intergerLength
	 *            整数部分的长度
	 */
	public void setIntergerLength(int intergerLength) {
		this.intergerLength = intergerLength;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 是否为小数
	 * 
	 * @return boolean
	 */
	public boolean isDecimal() {
		return isDecimal;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 设置是否为小数
	 * 
	 * @param isDecimal
	 *            是否为小数
	 */
	public void setDecimal(boolean isDecimal) {
		this.isDecimal = isDecimal;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 得到小数的长度
	 * 
	 * @return int
	 */
	public int getDecimalLength() {
		return decimalLength;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 设置小数的长度
	 * 
	 * @param decimalLength
	 *            小数的长度
	 */
	public void setDecimalLength(int decimalLength) {
		this.decimalLength = decimalLength;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 是否为密码
	 * 
	 * @return boolean
	 */
	public boolean isPassword() {
		return isPassword;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 设置是否为密码
	 * 
	 * @param isPassword
	 *            是否为密码
	 */
	public void setPassword(boolean isPassword) {
		this.isPassword = isPassword;
		if (isPassword) {
			this.setTransformationMethod(PasswordTransformationMethod
					.getInstance());
		}
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 设置输入方式
	 * 
	 * @param inputMethod
	 *            输入方式
	 */
	public void setInputMethod(int inputMethod) {
		this.inputMethod = inputMethod;
		View inflateView = inflater.inflate(R.layout.app_widget_keyboard, null);
		if (inputMethod == 2) {
			viewFlipper = new ViewFlipper(context);
			viewFlipper.addView(
					inflater.inflate(R.layout.app_widget_letter_keyboard, null), 0);
			inflateView.findViewById(R.id.relative_last_line).setVisibility(
					View.GONE);
			inflateView.findViewById(R.id.linear_last_line).setVisibility(
					View.VISIBLE);
			viewFlipper.addView(inflateView, 1);
			
			View charView = inflater.inflate(R.layout.app_widget_char_keyboard, null);
			charViewFlipper = (ViewFlipper)charView.findViewById(R.id.charViewFlipper);
			
			
			View charKeyBoardView1 = inflater.inflate(R.layout.app_widget_char_keyboard1, null);
			View charKeyBoardView2 = inflater.inflate(R.layout.app_widget_char_keyboard2, null);
			charViewFlipper.addView(charKeyBoardView1,0);
			charViewFlipper.addView(charKeyBoardView2,1);
			
			viewFlipper.addView(charView,2);
			
			keyBoardView = new KeyBoardView(viewFlipper,
					LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT,
					LETTERKEYBOARD, context);
		
		
		
		
		} else {
			keyBoardView = new KeyBoardView(inflateView,
					LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT,
					KEYBOARD, context);
		}

		keyBoardView.setOnKeyDownBtnListener(new OnKeyDownBtnListener() {
			@Override
			public void onKeyDownBtn(KeyEvent event) {
				APPLog.i("zbkc", "onKeyDownBtn:" + event);
				dispatchKeyEvent(event);
			}
		});

		keyBoardView.setOnKeyExitBtnListener(new OnKeyExitBtnListener() {
			@Override
			public void onKeyExitBtn() {

				hideKeyBoard();
			}
		});

		keyBoardView.setOnKeySureBtnListener(new OnKeySureBtnListener() {
			@Override
			public void onKeySureBtn() {
				// PAKeyBoardEditText.this.clearFocus();
				if (onBtnSureClickListener != null) {
					onBtnSureClickListener.onBtnSureClick();
				}
				hideKeyBoard();
			}
		});

		keyBoardView
				.setOnSwitchKeyBoardListenter(new OnSwitchKeyBoardListenter() {
					@Override
					public void onSwitchKeyBoard(int keyBoardType) {
						if (keyBoardType == 1) {
							keyBoardView.setKeyBoradType(2);
							viewFlipper.setDisplayedChild(1);
						} else if (keyBoardType == 2) {
							keyBoardView.setKeyBoradType(1);
							viewFlipper.setDisplayedChild(0);
						} else if(keyBoardType == 3) {
							viewFlipper.setDisplayedChild(2);
						}
					}
				});
		
		keyBoardView.setOnSwitchCharKeyBoardListener(new OnSwitchCharKeyBoardListener() {
			
			@Override
			public void onSwitchCharKeyBoard(int charKeyBoardType) {
				if(charKeyBoardType == 1) {
					charViewFlipper.setInAnimation(context, R.anim.app_widget_push_up_in);
					charViewFlipper.setOutAnimation(context, R.anim.app_widget_push_up_out);
					charViewFlipper.setDisplayedChild(0);
					
				}else if(charKeyBoardType == 2) {
					charViewFlipper.setInAnimation(context, R.anim.app_widget_push_down_in);
					charViewFlipper.setOutAnimation(context, R.anim.app_widget_push_down_out);
					charViewFlipper.setDisplayedChild(1);
				}
				
			}
		});
		

		keyBoardView.setAnimationStyle(android.R.style.Animation_InputMethod);

		keyBoardView.setEditText(this);

	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 得到输入方式
	 * 
	 * @return int
	 */
	public int getInputMethod() {
		return inputMethod;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 是否点击过
	 * 
	 * @return boolean
	 */
	public boolean isOnClick() {
		return isOnClick;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述]
	 * 
	 * @param isOnClick
	 *            设置是否点击
	 */
	public void setOnClick(boolean isOnClick) {
		this.isOnClick = isOnClick;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 是否能以零开头
	 * 
	 * @return boolean
	 */
	public boolean isStartZero() {
		return isStartZero;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 设置是否能以零开头
	 * 
	 * @param isStartZero
	 *            是否能以零开头
	 */
	public void setStartZero(boolean isStartZero) {
		this.isStartZero = isStartZero;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 是否能以点开头
	 * 
	 * @return boolean
	 */
	public boolean isStartPoint() {
		return isStartPoint;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 设置是否能以点开头
	 * 
	 * @param isStartPoint
	 *            是否能以点开头
	 */
	public void setStartPoint(boolean isStartPoint) {
		this.isStartPoint = isStartPoint;
	}

	/**
	 * 
	 * [构造简要说明]
	 * 
	 * @param context
	 *            上下文
	 * @param attrs
	 *            属性
	 * @param defStyle
	 *            样式
	 */
	public PAKeyBoardEditText(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		this.context = context;
		init();
	}

	/**
	 * 
	 * [构造简要说明]
	 * 
	 * @param context
	 *            上下文
	 * @param attrs
	 *            属性
	 */
	public PAKeyBoardEditText(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
		init();
	}

	/**
	 * 
	 * [构造简要说明]
	 * 
	 * @param context
	 *            上下文
	 */
	public PAKeyBoardEditText(Context context) {
		super(context);
		this.context = context;
		init();
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 初始化方法
	 */
	private void init() {
		this.setInputType(InputType.TYPE_NULL);

		// this.requestFocus();
		// this.setSelection(0);
		// this.setSelectAllOnFocus(true);
		// this.setSelected(true);
		// Selection.setSelection((Spannable)this, 0);
		Selection.selectAll(this.getText());
		imm = (InputMethodManager) getContext().getSystemService(
				Context.INPUT_METHOD_SERVICE);
		// Activity screenActivity = (Activity) getContext();
		// screenHeight =
		// screenActivity.getWindowManager().getDefaultDisplay().getHeight();
		WindowManager windowManager = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		screenHeight = windowManager.getDefaultDisplay().getHeight();
		inflater = LayoutInflater.from(context);

		setOnFocusChangeListener(this);
		setOnClickListener(this);
		sdkVersion = Build.VERSION.SDK_INT;
	}

	/**
	 * handler
	 */
	private Handler handler = new Handler();

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);

		if (sdkVersion > 10) {
			Paint p = getPaint();
			String text = getText().toString();
			float charWidth = 0.0f;
			/*if (text != null && !"".equals(text) && text.length() > 0) {
				charWidth = p.measureText(text.subSequence(0,
						getSelectionStart()).toString());
			}
			if (isPassword) {
				charWidth = text.subSequence(0, getSelectionStart()).toString()
						.length() * 8.0f;
			}*/
			
			if (text != null && !"".equals(text) && text.length() > 0) {
				
				if (isPassword) {
					//charWidth = text.subSequence(0, getSelectionStart()).toString().length() * 8.0f;
					charWidth = p.measureText(String.valueOf(DOT))*text.length();
					
					//charWidth = p.measureText(text.subSequence(0,getSelectionStart()).toString());
				} else {
					charWidth = p.measureText(text.subSequence(0,
							getSelectionStart()).toString());
				}
			}
			
			
			count++;
			count = count % 2;

			if (!isFocused()) {
				count = 1;
			}
			if (count == 0) {
				canvas.drawLine(charWidth, 0, charWidth, getHeight(), p);
			}
		} else {
			if (isFocused()) {
				handler.postDelayed(new Runnable() {
					@Override
					public void run() {
						invalidate();
					}
				}, 500);
			}
		}

	}

	/**
	 * 当sdk版本为3.0之后画关标的线程
	 */
	private Runnable drawCursorTask = new Runnable() {
		@Override
		public void run() {
			if (isFocusable()) {
				invalidate();
				handler.postDelayed(drawCursorTask, 500);
			}
		}
	};

	@Override
	public boolean dispatchKeyEvent(KeyEvent event) {

		// event.dispatch(this);
		// PABankLog.i("zbkc", "event dispatch");
		if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {

			ViewGroup view = (ViewGroup) getRootView();
			if (keyBoardView.isShowing()) {
				keyBoardView.dismiss();
				if (isMove) {
					resumeLayout(view);
				}
				return true;
			}

		}

		return super.dispatchKeyEvent(event);
	}

	@Override
	public void onFocusChange(View v, boolean hasFocus) {
		APPLog.i("zbkc", "onFocusChange event!!! FOCUSTAG:");
		((EditText) v).setInputType(InputType.TYPE_NULL);
		boolean isHide = imm.hideSoftInputFromWindow(this.getRootView()
				.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
		if (sdkVersion > 10) {
			if (hasFocus) {
				handler.post(drawCursorTask);
			} else {
				handler.removeCallbacks(drawCursorTask);
			}
		}
		if (inputMethod != -1) {
			if (onEditFocusListener != null) {
				onEditFocusListener.onEditFocus(hasFocus);
			}
			final ViewGroup view = (ViewGroup) this.getRootView();

			Handler handler = new Handler();
			if (hasFocus && this.hasWindowFocus()) {

				if (onEditOnClickListener != null) {
					onEditOnClickListener.onEditOnClick();
				}
				// PABankLog.i("zbkc", "imm.isActive:"+imm.isActive());

				// 设置时间解决 该键盘与系统键盘同时存在界面最下方时挤动布局覆盖输入框的bug
				int time = 200;
				if (isHide) {
					time = 600;
				}
				APPLog.i("zbkc", "time:" + time);
				handler.postDelayed(new Runnable() {
					@Override
					public void run() {
						calculateLayout(view, keyBoardView);

					}
				}, time);
				keyBoardView.showAtLocation(view, Gravity.BOTTOM
						| Gravity.CENTER_HORIZONTAL, LayoutParams.FILL_PARENT,
						LayoutParams.WRAP_CONTENT);
				if (inputMethod == 0) {
					keyBoardView.getBtnpoint().setEnabled(false);
					/*
					 * if (isPassword) {
					 * this.setTransformationMethod(PasswordTransformationMethod
					 * .getInstance()); }
					 */

				} else if (inputMethod == 1) {
					keyBoardView.getBtnpoint().setEnabled(true);
				} else if (inputMethod == 2) {
					// 全键盘
					// keyBoardView = new KeyBoardView(viewFlipper,
					// LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT,keyBoardType);
					/*
					 * if (isPassword) {
					 * this.setTransformationMethod(PasswordTransformationMethod
					 * .getInstance()); }
					 */
				}

				APPLog.i("zbkc", "hasFocus && this.hasWindowFocus()");

			} else {
				/*
				 * if (isPassword) {
				 * this.setTransformationMethod(PasswordTransformationMethod
				 * .getInstance()); }
				 */
				if (keyBoardView.isShowing()) {
					keyBoardView.dismiss();
				}
				if (isMove) {
					resumeLayout(view);
				}
			}
			/*
			 * else{
			 * 
			 * imm.showSoftInput(KeyBoardEditText.this, 0); }
			 */
		} else {
			// Log.i("zbkc", "inputMethod====="+inputMethod);
			// this.setInputType(InputType.TYPE_CLASS_TEXT);

		}
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 计算layout
	 * 
	 * @param view
	 * @param keyBoardView
	 */
	private void calculateLayout(ViewGroup view, KeyBoardView keyBoardView) {
		int keyBoardHeight = keyBoardView.getContentView().getHeight();
		this.getLocationInWindow(editLocations);
		// Log.i("zbkc", "getLocationInWindow" + editLocations[1]);
		int movePosition = editLocations[1] - (screenHeight - keyBoardHeight)
				+ PAKeyBoardEditText.this.getHeight();
		if (movePosition > 0) {
			// Log.i("zbkc", movePosition + "");
			scrollLayout(view, movePosition);
			isMove = true;
		}
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 恢复layout
	 * 
	 * @param view
	 */
	private void resumeLayout(ViewGroup view) {
		view.getChildAt(0).scrollTo(0, 0);
		view.postInvalidate();
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 滚动layout
	 * 
	 * @param view
	 * @param position
	 */
	private void scrollLayout(ViewGroup view, int position) {
		view.getChildAt(0).scrollTo(0, position);
		view.postInvalidate();
	}

	@Override
	public void onClick(View v) {
		((EditText) v).setInputType(InputType.TYPE_NULL);

		imm.hideSoftInputFromWindow(this.getRootView().getWindowToken(),
				InputMethodManager.HIDE_NOT_ALWAYS);
		if (onEditOnClickListener != null) {
			onEditOnClickListener.onEditOnClick();
		}
		if (inputMethod != -1) {
			APPLog.i("zbkc", "onClick event!!!");
			final ViewGroup view = (ViewGroup) this.getRootView();

			if (!keyBoardView.isShowing()) {
				imm.hideSoftInputFromWindow(
						this.getRootView().getWindowToken(),
						InputMethodManager.HIDE_NOT_ALWAYS);
				Handler handler = new Handler();
				handler.postDelayed(new Runnable() {

					@Override
					public void run() {
						calculateLayout(view, keyBoardView);

					}
				}, 200);
				keyBoardView.showAtLocation(view, Gravity.BOTTOM
						| Gravity.CENTER_HORIZONTAL, LayoutParams.FILL_PARENT,
						LayoutParams.WRAP_CONTENT);
				if (inputMethod == 0) {
					keyBoardView.getBtnpoint().setEnabled(false);
					/*
					 * if (isPassword) {
					 * this.setTransformationMethod(PasswordTransformationMethod
					 * .getInstance()); }
					 */
				} else if (inputMethod == 1) {
					keyBoardView.getBtnpoint().setEnabled(true);
				} else if (inputMethod == 2) {
					// 全键盘
					/*
					 * if (isPassword) {
					 * this.setTransformationMethod(PasswordTransformationMethod
					 * .getInstance()); }
					 */
				}

			}
			/*
			 * else{ imm.showSoftInput(KeyBoardEditText.this, 0); }
			 */
		} else {

			this.setInputType(InputType.TYPE_CLASS_TEXT);
		}
	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
		// Log.i("zbkc", "beforeTextChanged:" + s);
	}

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		String result = s.toString();
		APPLog.i("zbkc", "onTextChanged:" + result);
		if (onBtnShowStateListener != null) {
			APPLog.i("zbkc", "zbkc :onBtnShowStateListener");
			onBtnShowStateListener.onBtnShowState(true);
		}

		if (this.getText().toString().length() > 0 && this.isFocused()
				&& (inputMethod == 0 || inputMethod == 1)) {
			if (result.matches("^[0-9]*|[0-9]*\\.[0-9]*$")) {
				if (isStartZero == false) {
					if ("0".equals(result)) {
						s = "";
						this.setText(s);
					}
					if (result.contains(".")) {
						this.setText(result.subSequence(0, result.length() - 1));
						setSelection(getText().toString().length());
					}
				} else {
					if (!isDecimal && result.contains(".")) {
						this.setText(result.subSequence(0, result.length() - 1));
						setSelection(getText().toString().length());
					}
				}
				if (isStartPoint == false) {
					if (".".equals(result)) {
						s = "";
						this.setText(s);
					}
				}

				if (isDecimal == true) {

					if (getIntergerLength() > 0 && getDecimalLength() > 0) {
						if (result.contains(".")) {
							this.setFilters(new InputFilter[] { new InputFilter.LengthFilter(
									getIntergerLength() + getDecimalLength()
											+ 1) });
						} else if (!result.contains(".")) {
							this.setFilters(new InputFilter[] { new InputFilter.LengthFilter(
									getIntergerLength() + 1) });
							if (result.length() == (getIntergerLength() + 1)
									&& !".".equals(String.valueOf(result
											.charAt(getIntergerLength() - 1)))) {
								this.setText(result.subSequence(0,
										result.length() - 1));
								setSelection(getText().toString().length());
								return;
							}
						}
					}

					if (".".equals(result)) {
						s = "";
						this.setText(s);
					} else if (result.contains(".")) {
						char[] chars = result.toCharArray();

						if (!isContainsPoint(chars, ".")) {
							this.setText(result.subSequence(0,
									result.length() - 1));
							setSelection(getText().toString().length());
						}

					} else if ("0".equals(String.valueOf(result.charAt(0)))
							&& !deciamlStartZero) {
						this.setText(result + ".");
						setSelection(getText().toString().length());
						deciamlStartZero = true;
					}

					if (result.length() == 2
							&& "0".equals(String.valueOf(result.charAt(0)))
							&& !".".equals(String.valueOf(result.charAt(1)))) {
						this.setText("0");
						setSelection(getText().toString().length());
					}
				}

			} else {
				this.setText(result.subSequence(0, result.length() - 1));
				setSelection(getText().toString().length());
			}
		} else if ("".equals(result) || result == null) {
			deciamlStartZero = false;
			if (onBtnShowStateListener != null) {
				onBtnShowStateListener.onBtnShowState(false);
			}
		}

	}

	@Override
	public void afterTextChanged(Editable s) {

	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 是否包含点
	 * 
	 * @param chars
	 * @param str
	 * @return boolean
	 */
	private boolean isContainsPoint(char[] chars, String str) {
		int j = 0;
		int length = 0;
		for (int i = 0; i < chars.length; i++) {
			APPLog.i("zbkc", "char:" + chars[i]);
			if (str.equals(String.valueOf(chars[i]))) {
				j = j + 1;
				length = i + 1;
			}
		}
		// Log.i("zbkc", "jjjjjj:" + j);
		if (j > 1) {
			return false;
		} else if (j == 1 && (chars.length - length) > decimalLength) {

			return false;
		} else {
			return true;
		}

	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 删除按钮的监听状态
	 * 
	 * @author EX-XUJIAO001
	 * @version [Android PABank C01, 2012-2-15]
	 */
	public interface OnBtnShowStateListener {
		void onBtnShowState(boolean showState);
	}

	/**
	 * 监听器
	 */
	private OnBtnShowStateListener onBtnShowStateListener;

	public void setOnBtnShowStateListener(
			OnBtnShowStateListener onBtnShowStateListener) {
		this.onBtnShowStateListener = onBtnShowStateListener;
	}

	public OnBtnShowStateListener getOnBtnShowStateListener() {
		return onBtnShowStateListener;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 把焦点事件往外传
	 * 
	 * @author EX-XUJIAO001
	 * @version [Android PABank C01, 2012-2-15]
	 */
	public interface OnEditFocusListener {
		void onEditFocus(boolean hasFocus);
	}

	private OnEditFocusListener onEditFocusListener;

	public void setOnEditFocusListener(OnEditFocusListener onEditFocusListener) {
		this.onEditFocusListener = onEditFocusListener;
	}

	public OnEditFocusListener getOnEditFocusListener() {
		return onEditFocusListener;
	}

	/**
	 * 
	 * [一句话功能简述]<BR>
	 * [功能详细描述] 隐藏键盘
	 */
	public void hideKeyBoard() {
		ViewGroup view = (ViewGroup) PAKeyBoardEditText.this.getRootView();
		if (keyBoardView.isShowing()) {
			keyBoardView.dismiss();
			if (onHideKeyBoardListener != null) {
				onHideKeyBoardListener.onHideKeyBoard(true);
			}
			if (isMove) {
				resumeLayout(view);
			}
		}
	}

	public interface OnEditOnClickListener {
		void onEditOnClick();
	}

	private OnEditOnClickListener onEditOnClickListener;

	public void setOnEditOnClickListener(
			OnEditOnClickListener onEditOnClickListener) {
		this.onEditOnClickListener = onEditOnClickListener;
	}

	public interface OnHideKeyBoardListener {
		void onHideKeyBoard(boolean isHideKeyBoard);
	}

	private OnHideKeyBoardListener onHideKeyBoardListener;

	public void setOnHideKeyBoardListener(
			OnHideKeyBoardListener onHideKeyBoardListener) {
		this.onHideKeyBoardListener = onHideKeyBoardListener;
	}

	public interface OnBtnSureClickListener {
		void onBtnSureClick();
	}

	private OnBtnSureClickListener onBtnSureClickListener;

	public void setOnBtnSureClickListener(
			OnBtnSureClickListener onBtnSureClickListener) {
		this.onBtnSureClickListener = onBtnSureClickListener;
	}

	public OnBtnSureClickListener getOnBtnSureClickListener() {
		return onBtnSureClickListener;
	}
}
